import lombok.Getter;

import java.util.Iterator;

@Getter
public class TreeNode implements Iterable<TreeNode>{
    private final int value;
    private final TreeNode leftChild;
    private final TreeNode rightChild;

    public TreeNode(int value, TreeNode leftChild,TreeNode rightChild) {
        this.value = value;
        this.leftChild = leftChild;
        this.rightChild = rightChild;
    }

    public static void preOrderTraverse(TreeNode root) {
        if (root == null) {
            return;
        }
        System.out.print(root.value + " ");
        preOrderTraverse(root.leftChild);
        preOrderTraverse(root.rightChild);
    }


    @Override
    public Iterator<TreeNode> iterator() {
        return new TreeIterator(this);
    }
}
